'use strict';
module.exports = async (ctx, next) => {
  const user_id = ctx.session.user_id;
  if (user_id === undefined) {
    ctx.body = {
      code: 999,
      message: '没有登陆',
      data: null
    };
    return;
  }

  const mysql = ctx.app.mysql;

  const info = await mysql.get('jiaolan_admin_user', { id: user_id });
  if (info === null) {
    ctx.body = {
      code: -1,
      message: '登录失效',
      data: null
    };
    return;
  }

  ctx.user = info;
  await next();
};
